function [rests] = epsshift(funct,D,Ndata,N,eps)
% epsshift(funct,D,Ndata,N,eps)
% 
% 	Parameters:
% 		funct: 	function to produce the time series in question from
% 		D: 	initial displacement
% 		Ndata:	length of time series
% 		N:	kernel lenght for filter sample
% 		eps:	amount to peturb inital displacement by at each time step 
% 			in order to make displacement a function of time
% 	
% 	Outputs:
% 		rests	A time series that has been shifted by interpolation where displacement
% 			is a function of time, initial displacement, and epsilon.
% 
% 	Purpose of this code:  This code is an early formulation and has been superceeded by epsshiftnew2d
hold off;
%%
mesh = (1:Ndata);
ts = zeros(1,Ndata);
ts = funct(mesh);

%% Pass time series through FDtest using sinc
[Fconvh]= FDtesteps(ts,D,N,@sinc);

%% Pass time series through FDtest using sincdir
[Fpconvh]= FDtesteps(ts,D,N,@sincdir);

%% Create Linear Combination alpha = [1,eps] beta = [Fconvh, Fpconvh]
lc = zeros(1,Ndata);
for j=1:Ndata
    lc(j) = (Fconvh(j) + (j-1).*eps.*Fpconvh(j));
end
%lc = Fconvh + eps.*Fpconvh;

%% Create Normalizer
for j = 1:Ndata
    Dadj = D - (N-1)/2; 
    Dint = round(Dadj); 
    k = (-(N-1)/2):1:((N-1)/2); 
    s = (Dadj-Dint)-k; 
    w = getWindow('blackman3',N,D);
    p = sinc(s).*w;
    q = sincdir(s).*w;
    
    intf = (p + (j-1).*eps.*q);
    %intf = (p + eps*q);
    n = trapz(intf);

    %n = trapz((sinc(s)+eps.*sincdir(s)));

    %n = quadl(@quadfunct,s(1),s(end));
    %n = simpsons(@quadfunct,k(1),k(end),2024);

    %% Normalize lc
    rests(j) = lc(j)./n;
end


%% Plots
x1 = 1:length(ts);

%plot(x1,ts,'b');
%hold on;
%plot(x1,rests,'r');
%hold on;

%% Analytically Shift Time Series
tsa = zeros(1,Ndata);
for j = 1:Ndata
    tsa(j) = funct((j) - (D + (j-1).*eps));
end
%tsa = funct(mesh - (D + eps));

%plot(x1,tsa,'g');

%% Calculate Fractional Error
err = abs(tsa - rests)./abs(tsa);
shft = floor(D) + 1;

semilogy(x1,err,'g');
%plot(x1,err,'g');
xlim([D + (N-1);,length(ts)]);


end